<script>
	import { isLoggedIn } from '@/utils/user.js'
	import { cleanExpiredActions } from '@/utils/loginGuard.js'
	
	export default {
		onLaunch: function() {
			console.log('App Launch')
			
			// 清理过期的待执行操作
			cleanExpiredActions()
			
			// 检查登录状态
			if (isLoggedIn()) {
				// 获取当前页面路径
				const pages = getCurrentPages()
				if (pages.length > 0) {
					const currentPage = pages[pages.length - 1]
					const currentPath = '/' + currentPage.route
					
					// 如果当前在登录页面且已登录，跳转到首页
					if (currentPath === '/pages/login/index') {
						uni.reLaunch({
							url: '/pages/index/index'
						})
					}
				}
			}
		},
		onShow: function() {
			console.log('App Show')
			this.setShare();
			
			// 每次应用显示时也清理过期操作
			cleanExpiredActions()
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			setShare() {
				console.log('setShare')
				// 调用uni-app的分享API
				uni.showShareMenu({
					withShareTicket: true,
					menus: ['shareAppMessage', 'shareTimeline'],
					title: '枣庄红十字会',
					path: '/pages/index/index',
					desc: '欢迎使用枣庄红十字会',
					success: function () {
						console.log('分享成功');
					},
					fail: function (err) {
						console.error('分享失败', err);
					}
				});
			}	
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
	body{
		color: rgba(0, 0, 0, 0.80);
		font-size: 28rpx;
		background: #F6F6F6;
	}

	.primary-color{
		color: #F15941;
	}

	.primary-btn{
		width: 100%;
		height: 88rpx;
		background: url('@/static/btn-bg.png') no-repeat center center;
		background-size: 100% 100%;
		color: #fff;
		font-size: 28rpx;
		font-weight: 500;
		line-height: 88rpx;
		text-align: center;
		
		&.disabled {
			opacity: 0.6;
			pointer-events: none;
		}
	}

	 // 成功弹窗样式
	 .success-popup {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 9999999999;
        display: flex;
        align-items: center;
        justify-content: center;

        .popup-mask {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background: rgba(0, 0, 0, 0.5);
        }

        .success-popup-content {
            position: relative;
            width: 600rpx;
            min-height: 400rpx;
            background: #FFFFFF;
            border-radius: 24rpx;
            z-index: 1001;
            display: flex;
            flex-direction: column;
            align-items: center;
            padding: 40rpx 32rpx;

            .success-icon {
                width: 120rpx;
                height: 120rpx;
                margin-bottom: 30rpx;

                image {
                    width: 100%;
                    height: 100%;
                }
            }

            .success-title {
                font-size: 32rpx;
                font-weight: 600;
                color: rgba(0, 0, 0, 0.80);
                margin-bottom: 24rpx;
                line-height: 44rpx;
                text-align: center;
            }

            .success-message {
                font-size: 28rpx;
                color: rgba(0, 0, 0, 0.80);
                margin-bottom: 48rpx;
                line-height: 1.5;
				text-align: center;
            }

                         .success-btn {
                            width: 404rpx;
                            height: 108rpx;
                 display: flex;
                 align-items: center;
                 justify-content: center;
                 position: relative;
                 overflow: hidden;
                 background: url('./static/btn_bg.png') no-repeat center center;
                 background-size: 100% 100%;

                 .btn-text {
                     position: relative;
                     z-index: 1;
                     font-size: 32rpx;
                     font-weight: 500;
                     color: #FFFFFF;
                 }
             }
        }

		.browser-guide{
			width: 320rpx;
			height: 320rpx;
			margin-bottom: 54rpx;

			image{
				width: 320rpx;
				height: 320rpx;
			}
		}
    }
</style>
